import openai

# Initialize the OpenAI client
openai.api_key = "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"



while True:
    # Read the next prompt from the user
    user_input = input("You: ")

    # Exit the loop if the user types 'exit'
    if user_input.lower() == 'exit':
        print("Exiting the chat.")
        break

    # Check if the user wants to generate an image
    if user_input.lower().startswith("generate image"):
        image_prompt = user_input[len("generate image"):].strip()

        try:
            # Generate the image using the new OpenAI API
            response = openai.Image.create(
                prompt=image_prompt,
                n=1,  # Number of images to generate
                size="1024x1024"  # Image size, options: "256x256", "512x512", "1024x1024"
            )
            image_url = response['data'][0]['url']
            print("Image URL:", image_url)

        except Exception as e:
            print(f"Error generating image: {e}")
    else:
        print("Please start your request with 'generate image' to create an image.")
